  /**
   * 
   * @module description:后端从数据库根据监测点位操作元素信息文件
   * @author 吴迪嘉
   */
const theDatabase = require('../../config/db.js').theDb; //引入数据库
const projectInfoSchema = theDatabase.import('../../schema/project_info.js'); 
const locationphInfoSchema = theDatabase.import('../../schema/sample_detector_ground_info.js'); 
class ProjectInfoModel {

    static async getPhData(ground_number) {


    const AllProjectData = await locationphInfoSchema.findAll({
        where:{
            point_num: ground_number
        }
    })
    //  console.log(AllProjectData)
    return AllProjectData
}
static async getAllProjectData() {


    const AllProjectData = await projectInfoSchema.findAll()
    return AllProjectData
}

static async getProjecttypeByProjectnum(project_num) {


    const AllProjectData = await projectInfoSchema.findOne({
        where:{
            project_num: project_num
        }
    })
 
  
    
    return AllProjectData.project_type
}

static async UpdatedifferentCount(id,simple_count, detail_count,fixed_count,all_count) {

    await projectInfoSchema.update({
        simple_count: simple_count,
        detail_count:detail_count,
        fixed_count:fixed_count,
        all_count:all_count,
        
    },{
        where:{
            project_num:id
        }
    })
    return true
}

static async getCountByProjectnum(project_num) {


    const AllProjectData = await projectInfoSchema.findOne({
        where:{
            project_num: project_num
        }
    })
    var list={}
    list.simple_count=AllProjectData.simple_count
    list.detail_count=AllProjectData.detail_count
    list.fixed_count=AllProjectData.fixed_count
    list.all_count=AllProjectData.all_count

  
    
    return list
}
static async getDataByProjectnum(project_num) {


    var Alldata=[]
    for(let i of project_num){

    const AllProjectData = await projectInfoSchema.findAll({
        where:{
            project_num: i
        }
    })

    
    let res2 = AllProjectData.map(item=>{
    return item = item.dataValues
    })
    Alldata.push(res2[0])
    }
    return Alldata
    
    }
}
module.exports = ProjectInfoModel